package com.edu.exam.enums.questionbank;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 题库类型枚举
 *
 * <p>管理题库的分类类型，包括通用题库、学科题库、考试题库、练习题库等类型。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum QuestionBankType implements BaseEnum {

    /**
     * 通用题库
     */
    GENERAL("GENERAL", "通用题库"),

    /**
     * 学科题库
     */
    SUBJECT("SUBJECT", "学科题库"),

    /**
     * 考试题库
     */
    EXAM("EXAM", "考试题库"),

    /**
     * 练习题库
     */
    PRACTICE("PRACTICE", "练习题库"),

    /**
     * 模拟题库
     */
    MOCK("MOCK", "模拟题库"),

    /**
     * 模板题库
     */
    TEMPLATE("TEMPLATE", "模板题库"),

    /**
     * 共享题库
     */
    SHARED("SHARED", "共享题库"),

    /**
     * 私有题库
     */
    PRIVATE("PRIVATE", "私有题库");

    private final String code;
    private final String description;

    QuestionBankType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static QuestionBankType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Question bank type code cannot be null or empty");
        }

        for (QuestionBankType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown question bank type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static QuestionBankType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Question bank type description cannot be null or empty");
        }

        for (QuestionBankType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown question bank type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}